package com.example.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manager.domain.R;
import com.example.manager.domain.Ranks;
import com.example.manager.domain.SysDept;
import com.example.manager.service.RanksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/hris/pm")
@RestController
public class RanksController {

    @Autowired
    RanksService rankService;

    @GetMapping("/find")
    public R<Page> findRanks(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "2") Integer size,
            @RequestParam String rankNo,
            @RequestParam String rankArrangement,
            @RequestParam String rankArrangementName,
            @RequestParam String salaryCap,
            @RequestParam String salaryMinimum
    ){
        //创建分页对象
        Page<Ranks> page  = new Page<>(current,size);
        QueryWrapper<Ranks> queryWrapper = new QueryWrapper<>();
        if (rankNo!=null){
            queryWrapper.lambda().like(Ranks::getRankNo,rankNo);
        }
        if (rankArrangement!=null){
            queryWrapper.lambda().like(Ranks::getRankArrangement,rankArrangement);
        }
        if (rankArrangementName!=null){
            queryWrapper.lambda().like(Ranks::getRankArrangementName,rankArrangementName);
        }
        if (salaryCap!=null && !salaryCap.equals("")){
            queryWrapper.le("salary_cap",salaryCap);
        }
        if(salaryMinimum!=null && !salaryMinimum.equals("")){
            queryWrapper.ge("salary_minimum",salaryMinimum);
        }
        //根据分页对象，查询分页数据
        page = rankService.page(page,queryWrapper);
//        rankService.list(queryWrapper);
//        List<Ranks> c = rankService.findC(rankNo, rankArrangement,rankArrangementName,salaryCap,salaryMinimum);
        return R.success(page);
    }

    @PostMapping("/insert")
    public R<String> insert(@RequestBody Ranks ranks){
        rankService.save(ranks);
        return R.success("添加成功");
    }

    @PutMapping("/update")
    public R<String> update(@RequestBody Ranks ranks){
        rankService.updateById(ranks);
        return R.success("修过成功");
    }

    @DeleteMapping("/delete/{rankNo}")
    public R<String> delete(@PathVariable("rankNo") String id){
        rankService.removeById(id);
        return R.success("删除成功");
    }

}
